import { EventLevelItem, EventStatusItem, EventTableItem, EventTableParams } from './model/eventManagementModel';
import { workOrderHttp } from '/@/utils/http/axios';

enum Api {
  GET_EVENT_TABLE = '/v1/handler/page',
  GET_STATUS = '/v1/creator/status',
  GET_LEVEL = '/v1/handler/levelList',
}

export const getEventTable = async (params: EventTableParams) => {
  const res = await workOrderHttp.post<EventTableItem>({
    url: Api.GET_EVENT_TABLE,
    params,
  });
  res.records.map((item) => {
    item.source = item.isCirculated ? '自动流转' : '人工创建';
    return item;
  });
  return res;
};

export const getStatus = async () => {
  const res = await workOrderHttp.get<EventStatusItem[]>({
    url: Api.GET_STATUS,
  });
  res.map((item) => {
    return {
      label: item.description,
      value: item.statusCode,
    };
  });
  return res;
};

export const getLevel = async () => {
  const res = await workOrderHttp.get<EventLevelItem[]>({
    url: Api.GET_LEVEL,
  });
  res.map((item) => {
    return {
      label: item.description,
      value: item.level,
    };
  });
  return res;
};
